import type { BaseResponse } from '@/api/base'
import { getConfig } from '@/api/config'
import type { ExpressType } from '@/api/config/type'
import type { ResultType } from '@/api/base'
import { toast } from '@/utils/common'

export const deliveryTime: ResultType[] = [
  {
    name: '今天上午',
    value: 1,
    label: '今天上午'
  },
  {
    name: '今天下午',
    value: 2,
    label: '今天下午'
  },
  {
    name: '今天晚上',
    value: 3,
    label: '今天晚上'
  },
  {
    name: '尽快送达',
    value: 4,
    label: '尽快送达'
  },
  {
    name: '其他时间请备注',
    value: 5,
    label: '其他时间请备注'
  }
]
export const getDeliveryTime = (() => {
  return {
    1: '今天上午',
    2: '今天下午',
    3: '今天晚上',
    4: '尽快送达',
    5: '其他时间请备注'
  }
})

export const sexLimit: ResultType[] = [
  {
    name: '不限制性别',
    value: 0,
    label: '不限制性别'
  },
  {
    name: '仅限男生',
    value: 1,
    label: '仅限男生'
  },
  {
    name: '仅限女生',
    value: 2,
    label: '仅限女生'
  }
]

export const getSexLimit = (() => {
  return {
    0: '不限制性别',
    1: '仅限男生',
    2: '仅限女生'
  }
})

export const getApplyStatus = (() => {
  return {
    0: '未申请',
    1: '已申请',
    2: '已通过',
    3: '已拒绝',
  }
})

export const orderType: ResultType[] = [
  {
    label: '综合排序',
    value: null
  }, {
    label: '最新发布',
    value: 'create_time desc'
  }, {
    label: '低价优先',
    value: 'price asc'
  }, {
    label: '高价优先',
    value: 'price desc'
  }]

export const reqExpressType: () => Promise<ExpressType[]> = async () => {
  try {
    const res: BaseResponse = await getConfig('EXPRESS_TAKE_TYPE')
    return res.data as ExpressType[]
  } catch (error) {
    toast(error.tips)
    return []
  }
}